// Source file: D:\\Users\\afpa\\Documents\\workspace\\20-otarie\\src\\fr.afpa.biblio.dao\\AdherentsDao.java

package fr.afpa.biblio.dao;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;

import fr.afpa.biblio.exception.BiblioException;
import fr.afpa.biblio.metier.Adherent;
import fr.afpa.biblio.metier.EmpruntEnCours;

public class AdherentsDao {

	private ArrayList<Adherent> adherentList = new ArrayList<Adherent>();
	
	/**
	 * @roseuid 5240E3CF0093
	 */
	public AdherentsDao() {
		
		
		SimpleDateFormat sdf = new SimpleDateFormat("DD/MM/YYYY");
				
			
		try {
			adherentList.add(new Adherent("adh1", "pr1", sdf.parse("10/10/1980"), "h", 11, "pwd4", "pseu1", new ArrayList<EmpruntEnCours>(), "tel1"));
			adherentList.add(new Adherent("adh2", "pr2", sdf.parse("11/11/1981"), "h", 12, "pwd5", "pseu2", new ArrayList<EmpruntEnCours>(), "tel2"));
			adherentList.add(new Adherent("adh3", "pr3", sdf.parse("12/12/1982"), "h", 13, "pwd6", "pseu3", new ArrayList<EmpruntEnCours>(), "tel3"));
		}
		catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (BiblioException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @param id
	 * @return
	 */
	public Adherent findByKey(int id) {
		Iterator<Adherent> it;
		it = adherentList.iterator();

		while (it.hasNext()) {
			Adherent a = it.next();
			if (a.getIdUtilisateur() == id) return a;
		}
		return null;
	}
}